﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PositionType.aspx.cs" Inherits="Page_日常工作_PositionType" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="/Com/JS/easyUi/themes/icon.css" rel="stylesheet" />
    <link href="/Com/JS/easyUi/themes/default/easyui.css" rel="stylesheet" />
    <link href="/Com/JS/formValidator/css/template.css" rel="stylesheet" />
    <link href="/Com/JS/formValidator/css/validationEngine.jquery.css" rel="stylesheet" />
    <link href="/Com/CSS/default.css" rel="stylesheet" />
    <script src="/Com/JS/jquery-1.8.2.js"></script>
    <script src="/Com/JS/easyUi/jquery.easyui.min.js"></script>
    <script src="/Com/JS/Common.js"></script>
    <script src="/Com/JS/jquery.form.js"></script>
    <script src="/Com/JS/formValidator/js/jquery.validationEngine.js"></script>
    <script src="/Com/JS/formValidator/js/languages/jquery.validationEngine-zh_CN.js"></script>
    <script type="text/javascript">
        var optionProductList = {};
        //是否点击选择单元格标识
        var IsCheckFlag = true;
        $().ready(function () {
            $("#formAddTag").validationEngine();
            //产品标签列表
            var option = {
                iconCls: 'icon-save',
                idField: 'Id',
                nowrap: false,
                fit: true,
                striped: true,
                useRp: true,
                pageList: [1, 10, 15, 20],
                pageSize: 20,
                url: '/Handler/ProblemsTypeHandler.ashx?action=GetPositionTypesTable',
                loadMsg: '数据装载中......',
                queryParams: {},
                singleSelect: true,
                columns: [[
                    {
                        title: "操作",
                        field: "opt",
                        width: 160,
                        align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            var strOption = "";
                            strOption += '<a href="#" style="text-decoration:none;color:blue" onclick="SetInterface(\'' + rowData.Id + '\',\'' + rowData.Interfaces + '\');">设置接口权限</a>&nbsp&nbsp';
                            strOption += '<a href="#" style="text-decoration:none;color:blue" onclick="Edit(\'' + rowData.Id + '\',\'' + rowData.TypeName + '\');">修改</a>&nbsp&nbsp';
                            strOption += '<a href="#" style="text-decoration:none;color:blue" onclick="Delete(\'' + rowData.Id + '\');">删除</a>&nbsp&nbsp';

                            return strOption;
                        }
                    },
                    { title: '编号', field: 'Id', align: 'center', width: 120, hidden: true },
                    { title: '角色名称', field: 'TypeName', align: 'center', width: 120 },
                    { title: '添加日期', field: 'AddTime', align: 'center', width: 160 }

                ]],
                pagination: true,
                rownumbers: true,
                toolbar: [
                    {
                        id: 'btnAdd',
                        text: '添加',
                        iconCls: 'icon-add',
                        handler: function () {
                            $("#dialogAddTag").dialog("open");
                        }
                    }
                ],
                onSortColumn: function (sort, order) {
                    var queryParams = $('#dataList').datagrid('options').queryParams;
                    queryParams.SortName = sort;
                    queryParams.SortOrder = order;
                }
            };
            option.queryParams = { RP: option.pageSize };
            $("#dataList").datagrid(option);
            //分页实现
            var p = $('#dataList').datagrid('getPager');
            if (p) {
                $(p).pagination({
                    displayMsg: '当前显示从{from}到{to}共{total}记录',
                    beforePageText: "第",
                    afterPageText: "共 {pages}",
                    onBeforeRefresh: function (pageNumber, pageSize) {
                        $(this).pagination('loading');
                    },
                    onChangePageSize: function () {
                        var queryParams = $('#dataList').datagrid('options').queryParams;
                        queryParams.RP = $(p).pagination('options').pageSize;
                    },
                    onRefresh: function () {
                    },
                    onSelectPage: function (pageNumber, pageSize) {
                        var queryParams = $('#dataList').datagrid('options').queryParams;
                        queryParams.Page = pageNumber;
                        $("#dataList").datagrid('reload');
                    }
                });
            }

            //产品详细列表
            optionProductList = {
                iconCls: 'icon-save',
                idField: 'Id',
                nowrap: false,
                fit: true,
                striped: true,
                useRp: true,
                url: '',
                loadMsg: '数据装载中......',
                sortName: 'AddTime',
                sortOrder: 'asc',
                queryParams: {},
                singleSelect: false,
                columns: [[
                    { title: '编号', field: 'IDPlus', sortable: true, align: 'center', width: 110, checkbox: true },
                    { title: '接口名称', field: 'InterfaceName', sortable: true, align: 'center', width: 140 },
                    { title: '接口描述', field: 'Describe', sortable: true, align: 'center', width: 150 },
                ]],
                rownumbers: true,
                onSortColumn: function (sort, order) {
                    var queryParams = $('#dataListProduct').datagrid('options').queryParams;
                    queryParams.SortName = sort;
                    queryParams.SortOrder = order;
                },
                onLoadSuccess: function (row) {//当表格成功加载时执行               
                    var rowData = row.rows;
                    var index = 0;
                    var skus = $("#skus").val();
                    $.each(rowData, function () {//遍历JSON
                        if (skus.indexOf(rowData[index].Id) > -1) {
                            $("#dataListProduct").datagrid("selectRecord", rowData[index].Id); //如果数据行为已选中则选中改行
                        } else {
                            $("#dataListProduct").datagrid("unselectRow", index);
                        }
                        index++;
                    });
                },
                onClickCell: function (rowIndex, field, value) {
                    IsCheckFlag = false;
                },
                onSelect: function (rowIndex, rowData) {
                    if (!IsCheckFlag) {
                        IsCheckFlag = true;
                        $("#dataListProduct").datagrid("unselectRow", rowIndex);
                    }
                },
                onUnselect: function (rowIndex, rowData) {
                    if (!IsCheckFlag) {
                        IsCheckFlag = true;
                        $("#dataListProduct").datagrid("selectRow", rowIndex);
                    }
                }
            };

            //选择产品dialog设置
            $("#dialogSetProduct").dialog({
                title: "选择接口",
                width: 800,
                height: 550,
                buttons: [{
                    id: 'btnSetProduct',
                    text: '确定',
                    iconCls: 'icon-ok',
                    handler: function () {
                        //提交
                        var mySelect = $("#dataListProduct").datagrid("getSelections");
                        if (mySelect == null || mySelect.length <= 0) {
                            alert("请选择接口!");
                            return;
                        }
                        var skus = "";
                        for (var i = 0; i < mySelect.length; i++) {
                            skus = skus + mySelect[i].Id + ",";
                        }               
                        skus = skus.substring(0, skus.length - 1);
                        var idplus = $("#idplus").val();
                        if (confirm("确定授予所选权限么？")) {
                            var currentDate = new Date();
                            $.get('/Handler/ProblemsTypeHandler.ashx?action=AddInterfacesPosition', { NowDate: currentDate, Skus: skus, IDPlus: idplus }, function (data) {
                                var result = GetResult(data);
                                if (result.IsSuccess) {
                                    alert(result.Message);
                                } else {
                                    if (result.message != "") {
                                        alert(result.message);
                                    }
                                }
                                $("#dataListProduct").datagrid("reload");
                                $("#dataList").datagrid('reload');
                            });
                        }
                        $("#dataListProduct").datagrid("unselectAll");
                        $("#dialogSetProduct").dialog("close");
                        $("#dataList").datagrid('reload');
                    }
                },
                {
                    text: '关闭',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        $("#dialogSetProduct").dialog("close");
                    }
                }]
            });



            //添加产品标签异步表单
            var optionAddTag = {
                dataType: 'text',
                beforeSubmit: showRequest,
                error: showError,
                success: showResponse
            };
            $('#formAddTag').ajaxForm(optionAddTag);
            //添加产品标签
            $("#dialogAddTag").dialog({
                title: "添加职位",
                width: 700,
                height: 220,
                buttons: [{
                    id: 'btnAddTag',
                    text: '确定',
                    iconCls: 'icon-ok',
                    handler: function () {
                        //提交表单
                        if ($("#formAddTag").validationEngine('validate') == true) {
                            $("#btnAddTag").linkbutton('disable');
                            $("#formAddTag").submit();
                        }
                    }
                },
                    {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $("#dialogAddTag").dialog("close");
                        }
                    }]
            });


            //修改产品标签异步表单
            var optionEditTag = {
                dataType: 'text',
                beforeSubmit: showRequest,
                error: showError,
                success: showEditResponse
            };
            $('#formEditTag').ajaxForm(optionEditTag);
            //修改产品标签
            $("#dialogEditTag").dialog({
                title: "修改职位",
                width: 700,
                height: 220,
                buttons: [{
                    id: 'btnEditTag',
                    text: '确定',
                    iconCls: 'icon-ok',
                    handler: function () {
                        //提交表单
                        if ($("#formEditTag").validationEngine('validate') == true) {
                            $("#btnEditTag").linkbutton('disable');
                            $("#formEditTag").submit();
                        }
                    }
                },
                    {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $("#dialogEditTag").dialog("close");
                        }
                    }]
            });


        });



        //表单提交前
        function showRequest(formData, jqForm, options) {
            return true;
        }
        //表单提交出错
        function showError(data) {
            alert('提交出错！');
        }

        //添加产品标签成功
        function showResponse(data, status) {
            var result = GetResult(data);
            if (result.IsSuccess) {
                $("#dialogAddTag").dialog('close');
                document.getElementById("formAddTag").reset();
                $("#dataList").datagrid('reload');
                alert(result.Message);
            } else {
                if (result.Message != "") {
                    alert(result.Message);
                }
            }
            $("#btnAddTag").linkbutton('enable');
        }

        //修改产品标签成功
        function showEditResponse(data, status) {
            var result = GetResult(data);
            if (result.IsSuccess) {
                $("#dialogEditTag").dialog('close');
                document.getElementById("formEditTag").reset();
                $("#dataList").datagrid('reload');
                alert(result.Message);
            } else {
                if (result.Message != "") {
                    alert(result.Message);
                }
            }
            $("#btnEditTag").linkbutton('enable');
        }


        //修改产品标签
        function Edit(idplus, name) {
            $("#txtEditName").val(name);
            $("#formEditTag").attr("action", "/Handler/ProblemsTypeHandler.ashx?action=EditPositionTypes&IDPlus=" + idplus);
            $("#dialogEditTag").dialog("open");

        }


        //删除产品标签
        function Delete(id) {
            if (confirm("确定要删除吗？")) {
                $.get('/Handler/ProblemsTypeHandler.ashx?action=DeletePositionTypes&IDPlus=' + id, {}, function (data) {
                    var result = GetResult(data);
                    if (result.IsSuccess) {
                        alert(result.Message);
                        $("#dataList").datagrid("reload");
                    } else {
                        if (result.Message != "") {
                            alert(result.Message);
                        }
                    }
                });
            }
        }

        //设置接口
        function SetInterface(idplus, interfaces) {
            $("#idplus").val(idplus);
            $("#skus").val(interfaces);
            optionProductList.url = "/Handler/ProblemsTypeHandler.ashx?action=GetInterfacesTypes";
            $("#dataListProduct").datagrid(optionProductList);
            $("#dialogSetProduct").dialog("open");

        }

    </script>
</head>
<body class="easyui-layout" style="height: 95%; overflow: hidden; border: none;">
    <div region="center" border="false" style="margin-left: 5px; margin-top: 3px">
        <table id="dataList">
        </table>
    </div>
    <%-- 添加问题类型 --%>
    <div id="dialogAddTag" class="easyui_dialog" style="padding: 10px 10px;" closed="true">
        <form id="formAddTag" action="/Handler/ProblemsTypeHandler.ashx?action=AddPositionTypes" class="fm" method="post">
            <table cellpadding="3" cellspacing="1" style="width: 100%; margin: 0px auto; line-height: 26px;">
                <tr>
                    <td class="td-first">职位名称：</td>
                    <td class="td-second">
                        <input id="txtAddName" name="txtAddName" type="text" class="txt01 validate[required]" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
    
    <%-- 编辑问题类型 --%>
    <div id="dialogEditTag" class="easyui_dialog" style="padding: 10px 10px;" closed="true">
        <form id="formEditTag" action="/Handler/ProblemsTypeHandler.ashx?action=EditPositionTypes" class="fm" method="post">
            <table cellpadding="3" cellspacing="1" style="width: 100%; margin: 0px auto; line-height: 26px;">
                <tr>
                    <td class="td-first">职位名称：</td>
                    <td class="td-second">
                        <input id="txtEditName" name="txtEditName" type="text" class="txt01 validate[required]" />
                    </td>
                </tr>
                
            </table>
        </form>
    </div>

     <%--权限设置--%>
    <div id="dialogSetProduct" class="easyui_dialog" style="padding: 10px 10px;" closed="true">
        <div class="easyui-layout" style="height: 400px; width: 700px; overflow: hidden; border: 0.2px solid #95b8e7; margin: 0px auto;">
            <div region="center" border="false" style="">
                <table id="dataListProduct">
                </table>
            </div>
        </div>
        <input type="hidden" id="idplus" name="idplus" value="" />
        <input type="hidden" id="skus" name="skus" value="" />
    </div>

</body>
</html>